import { checkupgroupCreate } from "@/api/SecondmentDictionary";
import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicForm, FormSchema, useForm } from "@/components/Form";
import { message } from "antd";
import { useTranslation } from "react-i18next";
let reload: Function;
const index = (props: { register: Fn }) => {
	const { t } = useTranslation();
	const formSchema: FormSchema[] = [
		{
			label: t("felix_ui.grp_unit"),
			field: "grpName",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.date_from"),
			field: "contractId",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_addr"),
			field: "grpAddr",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_type"),
			field: "grpType",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1.outpatient service", value: "1" },
					{ label: "2.be in hospital", value: "2" }
				]
			},
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_subject"),
			field: "grpSubject",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1.Agency Medical Check-up", value: "1" },
					{ label: "2. Periodic Health Check-up", value: "2" },
					{ label: "3. Group Health Check-up", value: "3" },
					{ label: "4. Health Examination", value: "4" },
					{ label: "5. Paid Health Check-up", value: "5" },
					{ label: "6. CV 5028-NN", value: "6" },
					{ label: "7. CV 5029-NV", value: "7" }
				]
			},
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_fax"),
			field: "grpFax", //传真
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_email"),
			field: "grpEmail", //电子邮件
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("felix_ui.grp_tin"),
			field: "grpTin", //税号
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("contacts"),
			field: "contactPersonId", //联系人
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t("kevin_ui.startTime"),
			field: "dateFrom", //开始时间
			component: "DatePicker",
			colProps: { span: 12 }
		},
		{
			label: t("kevin_ui.endTime"),
			field: "dateTo", //结束时间
			component: "DatePicker",
			colProps: { span: 12 }
		}
	];
	const timeFn = (tiem: string) => {
		if (!tiem) return;
		const [date] = tiem.split(" ");
		return date;
	};
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("打开Drawer", data);
		reload = data.reload;
	});

	const [register, { getFieldsValue, resetFields }] = useForm({
		schemas: formSchema,
		labelWidth: 180
	});
	const handleSubmit = async () => {
		const formValue = await getFieldsValue();
		formValue.dateFrom = timeFn(formValue.dateFrom);
		formValue.dateTo = timeFn(formValue.dateTo);
		const res = await checkupgroupCreate(formValue);
		if (res) {
			message.success("This is a success message");
			resetFields();
			closeDrawer();
			reload();
		} else {
			message.error("This is an error message");
			return;
		}
	};
	return (
		<BasicDrawer showFooter={true} size="large" {...props} register={registerDrawer} ok={handleSubmit}>
			<BasicForm register={register}></BasicForm>
		</BasicDrawer>
	);
};
export default index;
